package ipc;

import java.io.File;

import rddl.RDDL;
import rddl.parser.ParseException;
import rddl.parser.parser;;

public class DecoupledMDPsTest {
	//take two unirings of 5
	//	solve each using val iter
	//solve combined using val iter
	//solve combined using val iter conc
	//measure time(reward possibly too)
	
	public DecoupledMDPsTest(final String domain_file, final String instance_prefix, 
			final int nparts) throws Exception {
		
		Logger logger = new Logger(instance_prefix+"_decoupled.log");
		RDDL domain = parser.parse(new File(domain_file));
		StringBuilder logstring = new StringBuilder();
		
		for( int size = 5; size <= 5 ; ++size ){
			logstring.append(size);
			logstring.append(" ");
			
			long sum = 0;
			
			for( int part = 0; part < nparts ; ++part ){
				RDDL inst = parser.parse(new File(instance_prefix+"_"+size+"_"+(part+1)+".rddl"));
				
				RDDL problem = new RDDL();
				problem.addOtherRDDL(domain);
				problem.addOtherRDDL(inst);

				long time = System.currentTimeMillis();
				new ValueIteration(problem , 0.1, ValueIteration.ORDER_GUESS, -1, "./", null);
				sum += (System.currentTimeMillis()-time);
			}

			logstring.append(sum);
			logstring.append(" ");
			
			RDDL combined = new RDDL();
			combined.addOtherRDDL(domain);
			combined.addOtherRDDL(parser.parse(new File(instance_prefix+"_"+size+"_combined.rddl")));
			
//			long time = System.currentTimeMillis();
//			new ValueIteration(combined, 0.1, ValueIteration.ORDER_GUESS, 1, "./");
//			logstring.append((System.currentTimeMillis()-time));
//			logstring.append(" " );
			
			long time = System.currentTimeMillis();
			new ValueIteration(combined, 0.1, ValueIteration.ORDER_GUESS, -1, "./",null);
			logstring.append((System.currentTimeMillis()-time));
			logstring.append(" " );
			
			
			time = System.currentTimeMillis();
			new ValueIterationConcurrent(combined, 0.1, ValueIteration.ORDER_GUESS, -1, "./", null);
			logstring.append((System.currentTimeMillis()-time));
			
			logger.log(logstring.toString());
		}		
		
	}
	
	public static void main(String[] args) throws Exception {
		
		String domain_file = "/scratch/final_comp/rddl/sysadmin_mdp.rddl";
		
		String inst_prefix = "/scratch/final_comp/rddl/sysadmin_uniring";//size_part/combined.rddl
		
		int nparts = 2;
		
		new DecoupledMDPsTest(domain_file, inst_prefix, nparts);
	}

	
}
